<?php
/*.  require_module 'standard'; .*/
require_once '/home/amemoryt/www/beta/lib/controllerWithoutGetOrPost.php';
$html = new Html();

$firstname = $html->text($_GET['firstname']);
if (empty($firstname)) {
    $firstname = 'First Name';
}
$lastname = $html->text($_GET['surname']);
if (empty($lastname)) {
    $lastname = 'Last Name';
}
	    
/* :TODO: Split function into DB, Model and View parts */
/* :TODO: Use process method instead */
/**
 * Get the newspaper publications
 * @return string
 */
function getPublications() {
    global $db, $html;
    $sql = "Select ID, ShortName, Name from Newspapers ORDER BY Name ASC";
    $result = $db->query($sql);
    $publications = '';
    $n = $db->rowCount($result);
    for ($i = 0; $i < $n; $i++) {
        $row = $db->fetch($result);
        $selected = '';
        if ($_GET['publication'] === $row['ShortName']) {
            $selected = ' selected="selected"';
        }
        $shortName = $html->text($row['ShortName']);
        $name = $html->text($row['Name']);
        $publications .= <<< EOT
                    <option$selected value="$shortName">$name</option>

EOT;
    }
    return $publications;
}
$publications = getPublications();

$fromDate = $html->text($_GET['from']);
if (empty($fromDate)) {
    $fromDate = 'From - dd/mm/yyyy';
}
$toDate = $html->text($_GET['to']);
if (empty($toDate)) {
    $toDate = 'To - dd/mm/yyyy';
}
echo <<< EOT
<div id="contentarea">
    <ul id="leftbar">
        <li>
            <h3><a href="member.php">Affiliate Login</a></h3>
            <p><a href="affiliates.php">Details?</a></p>
        </li>
        <li>
            <h3>Searching For?</h3>
            <form action="searchpeople.php" method="GET" onsubmit="return verifypeople(this)">
                <label>&nbsp;</label>
                <input name="firstname" id="firstname" value="$firstname" onfocus="removeText(this)"  onblur="resetText(this)" />
                <label>*</label>
                <input id="surname" name="surname" value="$lastname" onfocus="removeText(this)"  onblur="resetText(this)" />
                <label class="reqnote">* required</label>
                <input type="submit" class="gobutton" value="go" />
            </form>
        </li>
        <li class="alt">
            <h3>Search Newspaper Archive</h3>
            <form action="searchpublications.php" method="GET" onsubmit="return verifypublication(this)">
                <label>*</label>
                <select>
                    <option>Notice Type</option>
                    <option selected="selected">Death Notices</option>
                </select>
                <label>*</label>
                <select>
                    <option>Country</option>
                    <option selected="selected">New Zealand</option>
                </select>
                <label>*</label>
                <select name="publication" id="publication">
                    <option>Publication</option>
                    $publications
                </select>
                <label>*</label>
                <input name="from" id="from" value="$fromDate" onfocus="removeText(this)"  onblur="resetText(this)" />
                <label>*</label>
                <input name="to" id="to" value="$toDate" onfocus="removeText(this)"  onblur="resetText(this)" />
                <label class="reqnote">* required</label>
                <input type="submit" class="gobutton" value="go"/>
            </form>
        </li>
        <li class="linkitem">
            <a href="news.php" title="News">News</a>
        </li>
        <li class="linkitem">
            <a href="feedback.php" title="Place and View Feedback">Feedback</a>
        </li>
        <li class="linkitem">
            <a href="travel.php" title="Make Travel Arrangements">Make Travel Arrangements</a>
        </li>
        <li class="alt">
            <a title="Tell a Friend" class="browsernav_tellfriend" href="mailto:?subject=I wanted to tell you about this website&body=Hi, I wanted to tell you about this website http://www.amemorytree.co.nz Visit the site today and check out some of the features including being able to leave a message on someone's Remembrance Page, see if a lawyer is looking for you and read public notices in all NZ daily newspapers.">Tell a Friend</a>
            <br/>
        </li>
    </ul>
EOT;
?>
